require.config({
	paths : {
		"jquery" : "jquery-1.11.3",
		"cookie" : "cookie"
	}
});

define(["jquery","cookie"],function(){
	function fn(){		
		/*公告*/
		var timer = null;
		var i = 0;
		var liHeight = $(".showNotice li").height();
		function fnTimer(){
			timer = setInterval(function(){
				i++;
				if(i == $(".showNotice li").length){
					i = 1;
					$(".showNotice").css({"top":0});
				}
				console.log(i);
				$(".showNotice").stop().animate({"top":-i * liHeight},1000);
			},2000);
		}		
		fnTimer();		
		$(".showNotice a").hover(function(){
			clearInterval(timer);
		},function(){
			fnTimer();
		});
		
		/*搜索框失焦事件*/
		$("#sch").focus(function(){
			if($(this).val() != ""){
				$(this).val("");
			}
		});
		
		/*搜索框得焦事件*/
		$("#sch").blur(function(){
			if($(this).val() == ""){
				$(this).val("请输入商品名称或货号");
			}
		});
		
		/*右侧边栏*/
		$(".flyUser").mouseover(function(){
			$(".userHover").show();
			$(this).mouseout(function(){
				$(".userHover").hide()
				$(this).removeClass("aa");
			});
		});
		
		/*返回顶部*/
		$(".cb").click(function(){
			$(document).scrollTop = 0;
		})
		
		/*记住登录状态*/
		var uu = getCookie("loginedUsers");
		if(uu){
			$(".topRight li:first").html('<span>欢迎您，'+ uu +'</span>&nbsp;&nbsp;&nbsp;&nbsp;');
			$(".topRight li:eq(1) a").text("退出");
			$(".userHover p").html('<span><i style="color:#F70800">'+ uu +'</i>，你好！</span>');
		}
		$(".topRight li:eq(1) a").click(function(){
			removeCookie("loginedUsers");			
		});
		
		
		/*购物车*/
		$(".jiesuan").click(function(){
			if(getCookie("loginedUsers")){
				location.href = "cart.html";				
			}else{
				//alert("请先登录");
				location.href = "login.html";
			}
		});
				
		
	
		/*判断购物车中有无商品*/
		product = eval("(" + getCookie("product_1") + ")");
		if(product){
			$(".noneCart").hide();
			$(".haveCart").show();
			function addHtml(){
				product = eval("(" + getCookie("product_1") + ")");
				var text_html='';
				var totalMoney=0;
				$(".cartCon").html("");
				text_html+='<tr><td>'+product.name+'</td><td>'+product.price+'</td><td> '+product.num+' ';
				text_html+='</td><td>￥'+(product.price*product.num)+'</td></tr>';
				totalMoney+=product.price*product.num;
				$(".totalMoney").text(totalMoney);
				$(".cartCon").append(text_html);
				
				$(".iNum").text(product.num);
				$(".cartNum").text(product.num);
				
			}
			addHtml();
		}else {
			$(".noneCart").show();
			$(".haveCart").hide();
		}
		/*$(".add").each(function(){
			this.num = product.num;
			$(this).click(function(){				
				this.num ++;
				alert(this.num)
				var product = eval("(" + getCookie("product_1") + ")");
				var id = product.id;
				alert(id)
				var proName = product.name;
				var proPrice = product.price;
				alert(proName)
				alert(proPrice)
				var cookieValue = "{id:" + id + ',name:"'+ proName+ '",price:'+proPrice+ ",num:" + this.num + "}";
				var cookieKey = "product_" + id;
				setCookie(cookieKey,cookieValue,7);
				
				addHtml();
			})	
		})*/
	}
	return {
		fn : fn
	}
})


